<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8">
    <title>淘天机站群系统管理后台</title>
    <!-- include header_meta -->
</head>

<body>
    <!-- include header -->
    <div class="cp-wrap {if $jnarrow}jnarrow{/if}">
        <div class="crumb"> > 添加文章</div>
        <div class="cp-form postbox cl">
            <form method="POST" id="articleForm">
                <div class="box ml">
                    <div class="control-group">
                        <label class="control-label" for="name">标题：</label>
                        <div class="controls">
                            <input type="text" class="input-xlarge focused" name="title" style="width:100%;height:40px;line-height:40px;font-size:18px;font-weight:bold;" value="{$r[title]}"> </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="name">缩略图：</label>
                        <div class="controls">
                            <input id="thumb" type="text" class="input-xlarge focused" name="thumb" style="width:300px;" value="{$r[thumb]}"> <img id="imgsrc" style="margin-left:5px; vertical-align: middle; max-width: 150px; max-height: 60px; {if !$r[thumb]}display: none;{/if}" src="{$r[thumb]}" />
                            <div id="file_upload">上传</div>
                        </div>
                    </div>
                    <!--if A=='add'-->
                    <div class="control-group">
                        <label class="control-label" for="name">一键发布：</label>
                        <div class="controls">
                            <div>会发布到选中站点的相同栏目，不存在相同栏目则随机栏目。
                                <label style="color: red;">
                                    <input type="checkbox" class="allcheck">全选 </label>
                            </div>
                            <ul class="clearfix" style="border: 1px dashed #f96; padding: 10px; background: #fff9f9; margin-bottom: 10px;">
                                <!-- foreach $allyuming $v-->
                                <li style="width: 25%; float: left; margin-top: 5px;">
                                    <label>
                                        <input class="ymids" type="checkbox" name="ymids[]" value="{$v[id]}" {if is_array($r[ymids]) && in_array($v[ 'id'],$r[ymids])} checked="checked" {/if}>{$v[name]}</label>
                                </li>
                                <!-- /foreach -->
                            </ul>
                        </div>
                    </div>
                    <!-- /if -->
                    <div class="control-group">
                        <label class="control-label" for="name">内容：</label>
                        <div class="controls">
                            <script type="text/editor" style="width:100%;height:350px;" name="body" id="body" _type="editor">{$r[body]}</script>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="name">文章摘要：</label>
                        <div class="controls">
                            <textarea name="description" style="width:100%;height:90px;">{$r[description]}</textarea>
                        </div>
                    </div>
                    <!--if A=='add'-->
                    <div class="control-group">
                        <div class="controls"> <span class="tip">文章内容每10秒自动保存一次，关闭后重新进入此页面自动加载</span> </div>
                    </div>
                    <!-- /if -->
                </div>
                <div class="box mr">
                    <div class="small-group">
                        <input id="savebtn" type="button" class="btn" name="savebtn" value="{if A=='add'}发布{else}保存{/if}" />
                        <!--if A=='add'-->
                        <input id="draftbtn" type="button" class="btn btn-link" name="draftbtn" onclick="savedraft(1);" value="保存草稿" />
                        <!-- else -->
                        <input id="reviewbtn" type="submit" class="btn btn-link" name="reviewbtn" value="保存待审" />
                        <!-- /if -->
                    </div>
                    <div class="small-group" id="classbox">
                        <div class="controls-row">
                            <label class="small-label" for="class">所属栏目：</label>
                            <select name="class">
                                <option value="">选择栏目</option>
                                <!-- foreach $classlist $v -->
                                <option value="{$v[ename]}" {if $v[ 'ename']==$r[ 'class']} selected="selected" {/if}>{$v[title]}</option>
                                <!-- /foreach -->
                            </select>
                        </div>
                    </div>
                    <div class="small-group">
                        <div class="controls-row">
                            <label class="small-label" for="flag">自定义属性：</label>
                            <label>
                                <input type="radio" name="flag" id="flagsn" value="" {if $r[ 'flag']=='' }checked="checked" {/if}>无</label>
                            <label>
                                <input type="radio" name="flag" id="flagsh" value="h" {if $r[ 'flag']=='h' }checked="checked" {/if}>头条[h]</label>
                            <label>
                                <input type="radio" name="flag" id="flagsc" value="c" {if $r[ 'flag']=='c' }checked="checked" {/if}>推荐[c]</label>
                            <label>
                                <input type="radio" name="flag" id="flagsf" value="f" {if $r[ 'flag']=='f' }checked="checked" {/if}>幻灯[f]</label>
                            <label>
                                <input type="radio" name="flag" id="flagsa" value="a" {if $r[ 'flag']=='a' }checked="checked" {/if}>特荐[a]</label>
                            <label>
                                <input type="radio" name="flag" id="flagss" value="s" {if $r[ 'flag']=='s' }checked="checked" {/if}>滚动[s]</label>
                            <label>
                                <input type="radio" name="flag" id="flagsb" value="b" {if $r[ 'flag']=='b' }checked="checked" {/if}>加粗[b]</label>
                        </div>
                    </div>
                    <div class="small-group">
                        <div class="controls-row">
                            <label class="small-label" for="keyword">关键词：</label>
                            <input type="text" class="input-xlarge focused" name="keyword" value="{$r[keyword]}"> </div>
                    </div>
                    <div class="small-group">
                        <div class="controls-row">
                            <label class="small-label" for="tags">标签：</label>
                            <input type="text" class="input-xlarge focused" name="tags" value="{$r[tags]}"> </div>
                    </div>
                    <div class="small-group">
                        <div class="controls-row">
                            <label class="small-label" for="tags">发布时间：</label>
                            <input type="text" class="input-xlarge focused" name="diytime" value="{if empty($r['addtime'])}{date('Y-m-d H:i:s')}{else}{date('Y-m-d H:i:s',$r['addtime'])}{/if}"> </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <!-- include footer -->
    <div class="tipsbox">
        <div class="tipsinfo"> sdfs </div>
    </div>
    <style>
    .postbox { position: relative;}
    .postbox .ml { margin-right: 350px;}
    .postbox .mr { position: fixed; right: 20px; top: 135px; width: 300px; background: #F1F3F6;}
    .small-group { padding: 10px 0;}
    .small-group .btn { padding: 15px 30px; font-weight: bold;}
    .small-label { display: block; font-weight: bold;}
    .tipsbox { display: none; z-index: 19890101; position: fixed; background-color: rgba(0, 0, 0, 0.5);top: 0; left: 0; width: 100%; height: 100%; _height: expression(document.body.offsetHeight+"px");}
    .tipsbox .tipsinfo { position: fixed; width: 350px; top: 150px; left: 50%; margin-left: -175px; padding: 10px; line-height:2; background: #fff; text-align: center;border-radius: 2px; box-shadow: 1px 1px 50px rgba(0, 0, 0, .3);}
    </style>
    <script>
    var uploader = WebUploader.create({
        auto: true,
        swf: '__APPROOT__/js/webuploader.swf',
        server: '?m=upload&a=uploadimage',
        pick: '#file_upload',
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/*'
        }
    });
    uploader.on('uploadSuccess', function(file, res) {
        $("#imgsrc").show().attr("src", res.url);
        $("#file_upload").val(res.url);
        $("#thumb").val(res.url);
    });
    </script>
    <script>
    loadEditor();
    $(window).resize(function() {
        $(".edui-container").width("auto");
    });
    $(".cp-wrap").scroll(function() {
        UM.getEditor("body").setHeight();
    });
    $(function() {
        $(".allcheck").click(function() {
            if ($(this).prop("checked") == true) {
                $(".ymids").prop("checked", true);
            } else {
                $(".ymids").prop("checked", false);
            }
        });
    });
    var ymids = ['{$yuming_id}'];
    var doneCount = 0;
    var AllCount = 0;

    function ajaxsub(btnObj) {
        var btnObjTxt = btnObj.val();
        var formObj = $("#articleForm");
        if (!formObj.attr("action")) {
            var formAction = window.location.href;
        } else {
            var formAction = formObj.attr("action");
        }
        var formData = formObj.serialize();
        ymid = false;
        if (ymids) {
            ymid = ymids[0];
        }
        if (ymid == false) {
            return;
        }
        formData += "&ymid=" + ymid + "&" + btnObj.attr("name") + "=" + btnObj.val();
        btnObj.attr("disabled", true).val("正在提交");

        $.ajax({
            type: "POST",
            url: formAction ? formAction : window.location.href,
            data: formData,
            dataType: "json",
            success: function(data) {
                if (data.status == 1) {
                    if (btnObj.attr("name") == 'savebtn') {
                        doneCount++;
                        
                        $(".tipsbox").show();
                        $(".tipsinfo").html('正在发布' + Math.round(100 * doneCount / AllCount) + "%");

                        ymids.splice(0, 1);
                        console.log(ymids);
                        if (ymids.length>0) {
                            ymids = ymids.join(',');
                            ymids = ymids.split(',');
                            setTimeout(function() {
                                ajaxsub(btnObj);
                            },100);
                            return;
                        } else {
                           setTimeout(function() {
                                $(".tipsbox").hide();
                            },1250);
                           cpAlert(data.msg, data.status);

                           if (typeof data.redirect != 'undefined') {
                                if (typeof $.pjax != 'undefined') {
                                    $.pjax({ url: data.redirect, container: '.rightframe', fragment: 'body', timeout: 8000 });
                                } else {
                                    window.location.href = data.redirect;
                                }
                            }
                        }
                    }
                    return;
                } else {
                    cpAlert(data.errMsg, data.status);
                    if (typeof data.redirect != 'undefined') {
                        if (typeof $.pjax != 'undefined') {
                            $.pjax({ url: data.redirect, container: '.rightframe', fragment: 'body', timeout: 8000 });
                        } else {
                            window.location.href = data.redirect;
                        }
                    }
                }
                btnObj.attr("disabled", false).val(btnObjTxt);
            },
            error: function(data) {
                cpAlert(data.responseText.replace(/<\/?[^>]*>/g, ''), 0);
                btnObj.attr("disabled", false).val(btnObjTxt);
            }
        });
    }
    $("#savebtn,#draftbtn,#reviewbtn").click(function() {
        if ($(this).attr("name") == 'savebtn') {
            var ymidsObj = $('input.ymids:checked');
            for (var i = 0; i < ymidsObj.length; i++) {
                ymids.push(ymidsObj[i].value);
            }
            AllCount = ymids.length;
        }
        var btnObj = $(this);
        ajaxsub(btnObj);
        return false;
    });
    </script>
    <!--if A=='add'-->
    <script>
    function savedraft(ishsow = 0) {
        editor && editor.sync();
        $.post("?m=article&a=draft", $(".postbox form").serialize(), function() {
            if (ishsow) {
                cpAlert("草稿保存成功", 1);
            }
        });
    }
    setInterval(function() {
        savedraft();
    }, 10000);
    </script>
    <!-- /if -->
</body>

</html>